
#pragma once

#include "GLvec3.h"

template<typename T>
class GLplane
{
public:	
	GLvec3<T> n;
	T d;
public:
	void Normalize()
	{ 
		T l = n.Length();
		n.x/=l;
		n.y/=l;
		n.z/=l;
		d /= l;	
	}

	T GetDistance( const GLvec3<T>& v )  const 
	{
		return v.DotProd( n ) + d ;
	}

	T GetAbsDistance( const GLvec3<T>& v )  const 
	{
		return abs( v.DotProd( n ) + d);
	}

	bool IsOnPlane( const GLvec3<T>& v,float epsilon  = ON_EPSILON ) const 
	{
		T d = GetAbsDistance( v );

		if( d <= epsilon )
			return true;

		return false;

	}

	bool IsOnFrontSide( const GLvec3<T>& v,float epsilon  = ON_EPSILON ) const 
	{
		T d = GetDistance( v );

		if( d > epsilon )
			return true;

		return false;
	}

	bool IsOnBackSide( const GLvec3f& v,float epsilon = ON_EPSILON ) const 
	{
		T d = GetDistance( v );

		if( d< -epsilon )
			return true;

		return false;
	}
};

typedef GLplane<int> GLplanei; 
typedef GLplane<float> GLplanef; 
typedef GLplane<double> GLplaned; 
